let host = window.location.host;
// websocket 获取数据
//----------------------------- 工作人员 -------------------------------------
// let mobileUrl = 'ws:' + host + '/d/isworking/websocket';
let wsMobile = new WebSocket('ws:' + host + '/d/bigscreen/websocketisworkon');
// let wsMobile = new ReconnectingWebSocket(mobileUrl);
wsMobile.onclose = function () {
    // alert('移动端手机已关闭');
};
wsMobile.onmessage = mobileMessage;
wsMobile.onopen = () => {
    // alert('已重连');
};

function mobileMessage(evt) {
    // let str = evt.data;
    let con = JSON.parse(evt.data);
    let type = con.type;
    // if (type === 'isworking') {
    let data = con.data.mobile_list;
    let position_info = [];
    for (let item in data) {
        if (!data.hasOwnProperty(item)) continue;
        let position = data[item]['lnglat'];
        let name = data[item]['monitor'];
        let phone = data[item]['phonenumber'];
        let address = data[item]['address'];
        // let address="ss";
        position_info.push({
            position: position,
            name: name,
            mobile: phone,
            address: address
        });
    }
    render_point(position_info);
    // counterVue4.getnum();
    // counter4(position_info.length);
    counterVue4.setnum(position_info.length);
    // counterVue4.getnum();
    // vueSetData(counterVue4,position_info.length);
    // }
    // alert(data.code);
    // alert(str);

}

// ws.onopen = function(){
//     alert('yes');
// };

//     function (evt) {
//     // let str = evt.data;
//     let con = JSON.parse(evt.data);
//     let type = con.type;
//     if (type === 'isworking') {
//         let data = con.data;
//         let position_info = [];
//         for (let item in data) {
//             if (!data.hasOwnProperty(item)) continue;
//             let position = data[item]['location'];
//             let name = data[item]['name'];
//             let phone = data[item]['phone'];
//             let address = data[item]['address'];
//             position_info.push({
//                 position: position,
//                 name: name,
//                 mobile: phone,
//                 address: address
//             });
//         }
//         render_point(position_info);
//         // counterVue4.getnum();
//         // counter4(position_info.length);
//         counterVue4.setnum(position_info.length);
//         // counterVue4.getnum();
//         // vueSetData(counterVue4,position_info.length);
//     }
//     // alert(data.code);
//     // alert(str);
// };
// selectObj(massOBJ);
// massOBJ.setMap(map2);

//---------------------------- 海量点 -------------------------------------------
let massMarkUrl = 'ws:' + host + '/d/bigscreen/websocketmassmark';
// let ws_massMark = new ReconnectingWebSocket(massMarkUrl);
let ws_massMark = new WebSocket(massMarkUrl);


function massmarkMessage(evt) {
    let data = JSON.parse(evt.data);
    let massmark_data = data.massmark;
    let scroll = data.scroll;
    let heatmap_data = data.heatmap;
    // alert(scroll);
    // if (massmark_data.length > 0) {
    setMassMark(massmark_data, mass);
    // }
    chartScroll(scroll);
    heatMap(heatmap_data);
    // mass.setData(data.data);
    // selectObj(data.data);
    // alert(typeof(data.data));

}

ws_massMark.onopen = function () {
    // alert('yes');
};
ws_massMark.onmessage = massmarkMessage;
//     function (evt) {
//     let data = JSON.parse(evt.data);
//     let massmark_data = data.massmark;
//     let scroll = data.scroll;
//     let heatmap_data = data.heatmap;
//     setMassMark(massmark_data['data'], mass);
//     chartScroll(scroll);
//     heatMap(heatmap_data);
//     // mass.setData(data.data);
//     // selectObj(data.data);
//     // alert(typeof(data.data));
// };
ws_massMark.onclose = function () {
    // alert('海量点已关闭');
    location.replace([]);
};
ws_massMark.onerror = function () {
    // alert(this.readyState);
    // if(this.readyState===3){
    //     window.location.replace("islogin.html");
    // }
    location.replace([]);
};
// alert(host);
//---------------------------- 图表-----------------------------------------------
let chart_url = 'ws:' + host + '/d/bigscreen/websocketchart';
var wsChart = new WebSocket('ws:' + host + '/d/bigscreen/websocketchart');
// let wsChart = new ReconnectingWebSocket(chart_url);

wsChart.onmessage = chartmessage;
wsChart.onopen = () => {
    // alert('连接');
};
wsChart.onclose = () => {
    // alert('已断开');
    // location.replace([]);
};

// selectObj(wsChart);
function chartmessage(evt) {
    let data = JSON.parse(evt.data);
    let counter = data['counter'];
    let chart_year_month = data['chart_year_month'];
    let category = data['category'];
    let time_count = data['time_count'];
    // let scroll = data['scroll'];
    // let heatmap = data['heatmap'];
    setCounter(counter);
    chartYeatMonth(chart_year_month);
    chartCategory(category);
    chartTime(time_count);
    // chartScroll(scroll);
    // heatMap(heatmap);

}

// {
// let data = JSON.parse(evt.data);
// let counter = data['counter'];
// let chart_year_month = data['chart_year_month'];
// let category = data['category'];
// let time_count = data['time_count'];
// // let scroll = data['scroll'];
// // let heatmap = data['heatmap'];
// setCounter(counter);
// chartYeatMonth(chart_year_month);
// chartCategory(category);
// chartTime(time_count);
// // chartScroll(scroll);
// // heatMap(heatmap);
// };